package com.ruoyi.web.controller.background;

import com.ruoyi.background.domain.AppWorkImg;
import com.ruoyi.background.service.IAppWorkImgService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 健步风采照片Controller
 *
 * @author susu
 * @date 2024-09-04
 */
@RestController
@RequestMapping("/applet/workImg")
public class AppWorkImgController extends BaseController {
    @Autowired
    private IAppWorkImgService appWorkImgService;

    /**
     * 查询健步风采照片列表
     */
    @PreAuthorize("@ss.hasPermi('applet:workImg:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppWorkImg appWorkImg) {
        startPage();
        List<AppWorkImg> list = appWorkImgService.selectAppWorkImgList(appWorkImg);
        return getDataTable(list);
    }

    /**
     * 导出健步风采照片列表
     */
    @PreAuthorize("@ss.hasPermi('applet:workImg:export')")
    @Log(title = "健步风采照片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppWorkImg appWorkImg) {
        List<AppWorkImg> list = appWorkImgService.selectAppWorkImgList(appWorkImg);
        ExcelUtil<AppWorkImg> util = new ExcelUtil<AppWorkImg>(AppWorkImg.class);
        util.exportExcel(response, list, "健步风采照片数据");
    }

    /**
     * 获取健步风采照片详细信息
     */
    @PreAuthorize("@ss.hasPermi('applet:workImg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appWorkImgService.selectAppWorkImgById(id));
    }

    /**
     * 新增健步风采照片
     */
    @PreAuthorize("@ss.hasPermi('applet:workImg:add')")
    @Log(title = "健步风采照片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppWorkImg appWorkImg) {
        return toAjax(appWorkImgService.insertAppWorkImg(appWorkImg));
    }

    /**
     * 修改健步风采照片
     */
    @PreAuthorize("@ss.hasPermi('applet:workImg:edit')")
    @Log(title = "健步风采照片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppWorkImg appWorkImg) {
        return toAjax(appWorkImgService.updateAppWorkImg(appWorkImg));
    }

    /**
     * 修改规章制度状态
     */
    @PreAuthorize("@ss.hasPermi('applet:workImg:edit')")
    @Log(title = "规章制度", businessType = BusinessType.UPDATE)
    @GetMapping("/changeStatus/{id}/{status}")
    public AjaxResult editStatus(@PathVariable Long id, @PathVariable Integer status) {
        return toAjax(appWorkImgService.changeStatus(id, status));
    }

    /**
     * 删除健步风采照片
     */
    @PreAuthorize("@ss.hasPermi('applet:workImg:remove')")
    @Log(title = "健步风采照片", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appWorkImgService.deleteAppWorkImgByIds(ids));
    }
}
